#include "GhostAdjust.h"

GhostAdjust::GhostAdjust()
{
    //GhostObject::GhostObject();
}

void GhostAdjust::initalize(EGhostColor color,EGhostFaceState ghostFaceState,EGhostHandState ghostHandState, Vec2 position, float scale,bool isAutoChangeState,bool isAutoMove)
{
    GhostObject::initalize(color,ghostFaceState,ghostHandState, EGhostEyeColor::kGhostEyeColor_Random, position, scale, isAutoChangeState);
   // initLid();
    
    if(isAutoMove)
    {
        auto func = CallFuncN::create(CC_CALLBACK_0(GhostAdjust::Move,this));
        this->runAction(RepeatForever::create(Sequence::create(func,DelayTime::create(random(3.0f,8.0f)), NULL)));
        
    }
}

void GhostAdjust::Move()
{
    Vec2 p1 = Vec2(this->getPosition().x + random(-m_body->getContentSize().width*m_scale/3,m_body->getContentSize().width*m_scale/3),this->getPosition().y + random(-m_body->getContentSize().height*m_scale/3,m_body->getContentSize().height*m_scale/3));
    Vec2 p2 = Vec2(this->getPosition().x + random(-m_body->getContentSize().width*m_scale/3,m_body->getContentSize().width*m_scale/3),this->getPosition().y + random(-m_body->getContentSize().height*m_scale/3,m_body->getContentSize().height*m_scale/3));
    
    Vec2 p3 = this->getPosition();
    ccBezierConfig config;
    config.controlPoint_1 = p1;
    config.controlPoint_2 = p2;
    config.endPosition = p3;
    
    m_body->runAction(BezierTo::create(random(3.0f,8.0f), config));
}